#library "EnemyScouterThing"
#include "zcommon.acs"

str enemyname;
int enemyhealthmax;
int enemyhealth;
int monstercount;

script "EnemyScouterThing" ENTER
{
	if	(GetCvar( "bd_disablescanner") == 1) { terminate;}
	monstercount = GetLevelInfo (LEVELINFO_KILLED_MONSTERS);
	
	while(TRUE)
	{
	
		//NOTE:	PickActor requires careful handling. See the zdoom wiki about that!
		//		Actor's old TID needs to be saved, assigned a new TID, then restored back to old TID to keep things operational.
		int old_tid = PickActor(0, GetActorAngle(0), GetActorPitch(0), 2048.0, 0, MF_SHOOTABLE | !MF_CORPSE, ML_BLOCKEVERYTHING | ML_BLOCKHITSCAN, PICKAF_RETURNTID);
		
		int new_tid = UniqueTID();
	
		if(PickActor(0, GetActorAngle(0), GetActorPitch(0), 2048.0, new_tid, MF_SHOOTABLE | !MF_CORPSE, ML_BLOCKEVERYTHING | ML_BLOCKHITSCAN, PICKAF_FORCETID))
		{	
		
			//GET ACTOR INFO
			enemyname = GetActorProperty(new_tid, APROP_NameTag);			//name
			enemyhealthmax = GetActorProperty(new_tid, APROP_SpawnHealth);	//max hp
			enemyhealth = GetActorProperty(new_tid, APROP_HEALTH); 			//current hp
			int enemyarmor = CheckActorInventory(new_tid, "BasicArmor");  //armor
			
			int lightarmor = CheckActorInventory(new_tid, "haslightarmor");
			int mediumarmor = CheckActorInventory(new_tid, "hasmediumarmor");
			int heavyarmor = CheckActorInventory(new_tid, "hasheavyarmor");
			int platearmor = CheckActorInventory(new_tid, "hasplatearmor");
			

			//ACTOR HEALTH DISPLAY
		if(GetActorProperty(new_tid, APROP_Speed) > 0)
		{
			if (enemyhealth >= 1)
			{
				//ACTOR NAME DISPLAY
				setfont("smallfont");
				HudMessage(	s:"", 
						s:enemyname;
						HUDMSG_FADEOUT, 112223, CR_DARKRED, 0.5, 0.02, 0.6, 0.2);
			
				//ACTOR ARMOR DISPLAY
				if (enemyarmor >= 1)
				{
				  setfont("smallfont");
				  HudMessage(  s:"\n\n",
                  i:enemyarmor;
                  HUDMSG_FADEOUT, 112226, CR_DARKGREY, 0.5, 0.02, 0.6, 0.2);
				}
				
				if (CheckActorInventory(new_tid, "haslightarmor"))
				{
				  setfont("LITARMOR");
				  HudMessage(  s:"\n \n a"; HUDMSG_FADEOUT, 112229, CR_DARKGREY, 0.455, 0.0, 0.2, 0.2);
				}
				
				if (CheckActorInventory(new_tid, "hasmediumarmor"))
				{
				  setfont("MEDARMOR");
				  HudMessage(  s:"\n \n a"; HUDMSG_FADEOUT, 112229, CR_DARKGREY, 0.455, 0.0, 0.2, 0.2);
				}
				
				if (CheckActorInventory(new_tid, "hasheavyarmor"))
				{
				  setfont("HVYARMOR");
				  HudMessage(  s:"\n \n a"; HUDMSG_FADEOUT, 112229, CR_DARKGREY, 0.455, 0.0, 0.2, 0.2);
				}
				
				if (CheckActorInventory(new_tid, "hasplatearmor"))
				{
				  setfont("PLTARMOR");
				  HudMessage(  s:"\n \n a"; HUDMSG_FADEOUT, 112229, CR_DARKGREY, 0.455, 0.0, 0.2, 0.2);
				}
				
				// HEALTH COLOR
				int pc = enemyhealth * 100 / enemyhealthmax;
				
				setfont("MHEALTH");
				 HudMessage(  s:"\na"; HUDMSG_FADEOUT, 122229, CR_DARKGREY, 0.455, 0.02, 0.6, 0.2);
				
				if(pc>=75)
				{
				setfont("smallfont");				
					HudMessage(	s:"\n", d:enemyhealth;
					HUDMSG_FADEOUT, 112224, CR_TAN, 0.5, 0.02, 0.6, 0.2);	
				}
				else if(pc>=50)
				{
				setfont("smallfont");				
					HudMessage(	s:"\n", d:enemyhealth;
					HUDMSG_FADEOUT, 112224, CR_GOLD, 0.5, 0.02, 0.6, 0.2);	
				}
				else if(pc>=25)
				{
					setfont("smallfont");			
					HudMessage(	s:"\n", d:enemyhealth;
					HUDMSG_FADEOUT, 112224, CR_ORANGE, 0.5, 0.02, 0.6, 0.2);	
				}
				else if(pc>=0)
				{
					setfont("smallfont");			
					HudMessage(	s:"\n",d:enemyhealth;
					HUDMSG_FADEOUT, 112224, CR_RED, 0.5, 0.02, 0.6, 0.2);	
				}
				
				//ACTOR FRIENDLY INDICATOR	
				if(GetActorProperty(new_tid, APROP_Friendly) == TRUE)
				{
					setfont("smallfont");			
					HudMessage(	s:"\n\n-Friendly-";
								HUDMSG_FADEOUT, 112225, CR_GREEN, 0.5, 0.02, 0.6, 0.2);
				}
			} 
		}			
			Thing_ChangeTID(new_tid, old_tid);
		}
		Delay(1);
	}
}
